package com.thinta.wind.ui.home.adapter

import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.thinta.wind.R
import com.thinta.wind.databinding.FollowContentItemViewBinding
import com.thinta.wind.entity.HomeRecommendItemListBean


/*********************************************************
 * 版权信息：2021/6/29 14:42北京振中电子技术有限公司版权所有<p>
 * 创建作者：Wind<p>
 * 创建日期：2021/6/29 14:42<p>
 * *******************************************************<p>
 * 更新历史：    作者      日期      更新摘要<p>
 * <p>
 * *******************************************************<p>
 * 类功能说明：<p>
 */
class FollowAdapter(list: MutableList<HomeRecommendItemListBean>) : BaseQuickAdapter<HomeRecommendItemListBean, BaseViewHolder>(R.layout.follow_content_item_view, list), LoadMoreModule {

    private lateinit var mBinding : FollowContentItemViewBinding

    override fun convert(holder: BaseViewHolder, item: HomeRecommendItemListBean) {
        mBinding = initViewBinding(holder.itemView) as FollowContentItemViewBinding
        mBinding.itemTitle.visibility = View.GONE
        mBinding.themeHeaderLayout.visibility = View.GONE
        mBinding.themeLayout.visibility = View.GONE
        when{
            item.type.equals("textCard", true) -> mBinding.itemTitle.visibility = View.VISIBLE
            item.type.equals("followCard", true) -> mBinding.themeHeaderLayout.visibility = View.VISIBLE
            item.type.equals("videoSmallCard", true) -> mBinding.themeLayout.visibility = View.VISIBLE
        }
        mBinding.item = item
//        mBinding.root.setOnClickListener {
//            listener.onItemClick(layoutPosition, it)
//        }
    }
}

private fun initViewBinding(itemView: View) : ViewDataBinding? =
    if (null == DataBindingUtil.getBinding(itemView)) {
        DataBindingUtil.bind(itemView)
    } else {
        DataBindingUtil.getBinding(itemView)
    }